<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.io.PrintWriter, java.util.Calendar, java.sql.ResultSet, 
    		cn.edu.nju.software.model.administrator.DisplayManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	String administratorName = (String) application.getAttribute("administratorName");
	if (administratorName == null || administratorName.equals("")) {
		PrintWriter printWriter = response.getWriter();
		printWriter.println("<script>alert('Please login first!');" + 
							"window.location.href='index.jsp';</script>");
	}
%>

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<link type="text/css" rel="stylesheet" href="../css/administrator/display.css" />
	<link type="text/css" rel="stylesheet" href="../css/administrator/menu.css" />
	<link type="text/css" rel="stylesheet" href="../css/administrator/footer.css" />
	<title>放映管理</title>
</head>

<body>
	<div id="menu">
		<a href="administrator.jsp"><img src="../images/administrator/menu/menu_homepage.png" alt="首页" /></a>
		<a href="member.jsp"><img src="../images/administrator/menu/menu_member.png" alt="会员管理" /></a>
		<a href="display.jsp"><img src="../images/administrator/menu/menu_display.png" alt="放映管理" /></a>
		<a href="ticket.jsp"><img src="../images/administrator/menu/menu_ticket.png" alt="售票" /></a>
		<a href="statistics.jsp"><img src="../images/administrator/menu/menu_statistics.png" alt="统计分析" /></a>
		<a href="information.jsp"><img src="../images/administrator/menu/menu_information.png" alt="信息" /></a>
		<a href="index.jsp"><img src="../images/administrator/menu/menu_logout.png" alt="注销" /></a>
	</div>
	
	<div id="content">
	
		<div id="display_show">
			<div class="cell_title">已有的放映计划</div>
			<div class="display_cell">
				<table>
					<tr>
						<th>放映室</th>
						<th>状态</th>
						<th>影片</th>
						<th>时间</th>
						<th>容纳人数</th>
						<th>剩余票数</th>
						<th>票价</th>
					</tr>
					<%
					DisplayManager displayManager = new DisplayManager();
					ResultSet rs = displayManager.fetchAllDisplays();
					if (rs != null) {
						while (rs.next()) {
							String hall = rs.getString(2);
							String movie = rs.getString(3);
							String time = rs.getString(4);
							String[] times = time.split("[/:-]");
							String minute = times[3];
							if (minute.length() == 1) {
								minute = "0" + minute;
							}
							String time_str = times[0] + "月 " + times[1] + "日 " + times[2] + ":" + minute;
							
							int capacity = rs.getInt(5);
							int status = rs.getInt(6);
							String status_str = "";
							if (status == 1) {
								status_str = "启用";
							} else {
								status_str = "禁用";
							}
							int surplus = rs.getInt(7);
							int price = rs.getInt(8);
							
							int row = rs.getRow();
							if (row % 2 == 0) {
								%>
								<tr class="color_row">
									<td><%= hall %></td>
									<td><%= status_str %></td>
									<td><%= movie %></td>
									<td><%= time_str %></td>
									<td><%= capacity %></td>
									<td><%= surplus %></td>
									<td><%= price %></td>
								</tr>
								<%
							} else {
								%>
								<tr>
									<td><%= hall %></td>
									<td><%= status_str %></td>
									<td><%= movie %></td>
									<td><%= time_str %></td>
									<td><%= capacity %></td>
									<td><%= surplus %></td>
									<td><%= price %></td>
								</tr>
								<%
							}
						}
					}
					%>
				</table>
			</div>
		</div>
	
		<div id="display_manage">
			<div class="cell_title">制定放映计划</div>
			<div class="display_cell">
				<form method="post" action="../DisplayManage.do">
					<table>
						<tr class="color_row">
							<td>放映室</td>
							<td>
								<select name="hall">
									<%
									String[] halls = displayManager.fetchAllHalls();
									for (int i = 0; i < halls.length; i++) {
										String hall = halls[i];
										%>
										<option value=<%= hall %>><%= hall %></option>
										<%
									}
									%>
								</select><br />
							</td>
						</tr>
						<tr>
							<td>影片</td>
							<td><input type="text" name="movie" value="" /></td>
						</tr>
						<tr class="color_row">
							<td>时间</td>
							<td>
								<select name="month">
									<%
									for (int i = 1; i <= 12; i++) {
										String month = "" + i;
										%>
										<option value=<%= month %>><%= month %></option>
										<%
									}
									%>
								</select>&nbsp;月&nbsp;
								<select name="day">
									<%
									for (int i = 1; i <= 31; i++) {
										String day = "" + i;
										%>
										<option value=<%= day %>><%= day %></option>
										<%
									}
									%>
								</select>&nbsp;日&nbsp;<br />
								<select name="hour">
									<%
									for (int i = 0; i < 24; i++) {
										String hour = "" + i;
										%>
										<option value=<%= hour %>><%= hour %></option>
										<%
									}
									%>
								</select>&nbsp;时&nbsp;
								<select name="minute">
									<%
									for (int i = 0; i < 60; i++) {
										String minute = "" + i;
										%>
										<option value=<%= minute %>><%= minute %></option>
										<%
									}
									%>
								</select>&nbsp;分&nbsp;
							</td>
						</tr>
						<tr>
							<td>容纳人数</td>
							<td><input type="text" name="capacity" value="300" />&nbsp;人&nbsp;</td>
						</tr>
						<tr class="color_row">
							<td>剩余票数</td>
							<td><input type="text" name="surplus" value="300" />&nbsp;张&nbsp;</td>
						</tr>
						<tr>
							<td>票价</td>
							<td><input type="text" name="price" value="20" />&nbsp;元&nbsp;</td>
						</tr>
						<tr class="color_row">
							<td>操作</td>
							<td>
								<input type="radio" name="status" value="1" checked="checked" />&nbsp;启用&nbsp;
								<input type="radio" name="status" value="0" />&nbsp;停用&nbsp;
							</td>
						</tr>
						<tr>
							<td></td>
							<td>
								<input type="submit" value="确定" />
								<input type="reset" value="重新填写" />
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	
	</div>
	
	<div id="footer">
		<p>
			Copyright &copy; <a href="mailto:zyy08@software.nju.edu.cn">张迎亚</a>·南京大学·软件学院·2011春节
		</p>
	</div>
	
</body>

</html>